package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.example.demo.entity.UserLogInfo;
import com.example.demo.service.KafkaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Slf4j
public class KafkaAsyncProducerController {

    @Autowired
    KafkaService kafkaService;


    @GetMapping("/send/{msg}")
    public void send(@PathVariable String msg) {
        //解析前端用户的动作
        UserLogInfo userLogInfo = JSON.parseObject(msg, UserLogInfo.class);

        //业务逻辑
        log.info("用户进行的动作为：{}",userLogInfo.getAction());

        //将用户的动作信息传到kafka
        kafkaService.send(userLogInfo);

    }
}
